home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / color.arc / COLOR1.ASM < prev   
Assembly Source File  |  1987-01-08  |  23KB  |  470 lines

  1. TITLE   COLOR   January 7, 1987
  2. ;
  3. ;        Note: This version is slightly different from the COLOR.COM
  4. ;              Program furnished.  It does not include the procedure
  5. ;              for determining available computer memory.  This
  6. ;              procedure has nothing to do with the COLOR program and
  7. ;              I wish to keep it proprietary.
  8. ;
  9. ;        Happy programming,
  10. ;                                       Jeff Kallevig
  11. ;                                       Crestwood Elite
  12. ;                                       9804 Dell Road
  13. ;                                       Eden Prairie, MN  55344
  14. ;
  15. ;
  16. ;        COLOR.ASM                      -- Memory resident screen color --
  17. ;        ---------                      ----------------------------------
  18.  
  19. Code    SEGMENT PARA PUBLIC 'CODE'      ; Code segment begins here
  20.         ASSUME  CS:Code, DS:Code, ES:Code, SS:Code
  21.         ORG     100h                    ; Directive needed for .COM programs
  22.  
  23. Start:  JMP     Loader                  ; Skip down to the program
  24.  
  25.         DB      13
  26. Logo    DB      '╔═══════════════════════════════════╗', 13,10
  27. Header  DB      '║ COLOR POWER          Version 1.?? ║', 13,10
  28. Footer  DB      '║                                   ║', 13,10
  29.         DB      '║ Copyright 1986 by Crestwood Elite ║', 13,10
  30.         DB      '╚═══════════════════════════════════╝', 13,10
  31. EndLogo DB      26
  32.  
  33. NewColor DB     7                       ; Screen (Text) color
  34. Border  DB      0                       ; Default border color
  35. Int10h  DD      ?                       ; The original 10h Interrupt address
  36.  
  37. Video:  CMP     AH,6                    ; Scroll Window Up ?
  38.         JE      NewUpDn                 ;   Yes, so do NewUpDn.
  39.         CMP     AH,7                    ; Scroll Window Down ?
  40.         JE      NewUpDn                 ;   Yes, so do NewUpDn.
  41.         CMP     AH,0                    ; Set Video Mode ?
  42.         JE      NewMode                 ;   Yes, so do NewMode.
  43.         CMP     AH,9                    ; Write Character and Attribute ?
  44.         JNE     Display                 ;   No, so all done
  45.         CMP     BL,7                    ;   Yes, so is character Light Grey ?
  46.         JNE     Display                 ;     No, so all done
  47.         MOV     BL,CS:NewColor          ;     Yes, so substitute NewColor.
  48.  
  49. Display: JMP    CS:Int10h               ; All done, do original Interrupt 10h.
  50.  
  51. NewUpDn: CMP    BH,7                    ; Is color set to Light Grey ?
  52.         JNE     NewMode                 ;   No, so don't change it.
  53.         MOV     BH,CS:NewColor          ;   Yes, so substitute NewColor
  54.  
  55. NewMode: PUSHF                          ; Simulate the Video Interrupt
  56.         CALL    CS:Int10h               ;   by calling the original Interrupt.
  57.  
  58.         PUSH    DX                      ; Preserve these registers.
  59.         PUSH    AX
  60.  
  61.         MOV     DX,03D9h                ; Set the CGA I/O Port
  62.         MOV     AL,CS:Border            ;   to the Border Color
  63.         OUT     DX,AL                   ;   by writing directly to it.
  64.  
  65.         POP     AX                      ; Restore these registers.
  66.         POP     DX
  67.         IRET                            ; Return to the caller.
  68.  
  69. ;****************************************************************************
  70.                                         ;                                    *
  71. EndRes  LABEL   BYTE                    ; End of resident part of program    *
  72.                                         ;                                    *
  73. ;****************************************************************************
  74.  
  75. ;-----------------------------------------------------------------------------
  76. ;        ErrMsg displays the message. ( Does not preserve any registers! )
  77. ;
  78. ;        Entry: SwapBX    -- must contain OFFSET address of the message
  79. ;               SwapCX    -- must contain length of message (^Z also ends msg)
  80. ;               Color     -- the attribute for the message
  81. ;-----------------------------------------------------------------------------
  82.  
  83. SwapBX  DW      0                       ; Temp storage for BX
  84. SwapCX  DW      0                       ; Temp storage for CX
  85. Color   DB      30                      ; Yellow on Blue
  86.  
  87. ErrMsg  PROC    NEAR
  88.         PUSH    CX
  89.         MOV     AH,15                   ; Get page and mode numbers
  90.         INT     10h                     ;   by calling BIOS.
  91.         CMP     Color,0                 ; Check color flag
  92.         JNE     SetColor                ;   If not 0, then set to color number
  93.         MOV     AH,8                    ; Read Character and Attribute
  94.         INT     10h                     ;   by calling BIOS.
  95.         MOV     BL,AH                   ; Set to the original screen color
  96.         JMP     ShowMsg                 ;   and skip down
  97.  
  98. SetColor:
  99.         MOV     BL,112                  ; Default to monochrome reverse video
  100.         CMP     AL,7                    ;   Is it set for monochrome ?
  101.         JE      ShowMsg                 ;     Yes, then skip down.
  102.         MOV     BL,Color                ;     No, set to Color
  103.  
  104. ShowMsg:
  105.         MOV     AH,3                    ; Read Cursor Position
  106.         INT     10h                     ;   by calling BIOS.
  107.         XCHG    SwapBX,BX               ; Preserve page & color, set index
  108.         MOV     CX,SwapCX               ; Counter for message string
  109.  
  110. DisplayLoop:
  111.         MOV     SwapCX,CX               ; Preserve character counter
  112.         MOV     AL,[BX]                 ; Put the message char into AL
  113.  
  114.         CMP     AL,13                   ; Is it carriage return ?
  115.         JE      CarRet                  ;   Yes, so skip down.
  116.         CMP     AL,10                   ; Is it a line feed ?
  117.         JE      LineFeed                ;   Yes, so skip down.
  118.         CMP     AL,9                    ; Is it a tab ?
  119.         JE      TabOver                 ;   Yes, so move cursor over.
  120.         CMP     AL,26                   ; Is it a ^Z EOF marker ?
  121.         JE      EndMsg                  ;   Yes, then all done.
  122.  
  123.         MOV     AH,9                    ; Write Character & Attribute.
  124.         MOV     CX,1                    ;   write the character once
  125.         XCHG    BX,SwapBX               ;   Restore BX, put index into SwapBX
  126.         INT     10h                     ;   by calling BIOS.
  127.  
  128.         INC     DL                      ; Advance the cursor.
  129.  
  130. NewPosition:
  131.         MOV     AH,2h                   ; Set Cursor Position
  132.         INT     10h                     ;   by calling BIOS.
  133.  
  134.         XCHG    SwapBX,BX               ; Restore index BX, put BX in SwapBX
  135.         INC     BX                      ; Advance the index count
  136.         MOV     CX,SwapCX               ; Restore character counter
  137.         LOOP    DisplayLoop             ;   Continue to display more.
  138.         JMP     EndMsg                  ; All done here.
  139.  
  140. CarRet:
  141.         XCHG    BX,SwapBX               ;   Restore BX, put index into SwapBX
  142.         MOV     DL,0                    ; Cursor set to first column
  143.         JMP     NewPosition             ;   and continue.
  144.  
  145. LineFeed:
  146.         XCHG    BX,SwapBX               ;   Restore BX, put index into SwapBX
  147.         INC     DH                      ;   No, so just continue.
  148.         JMP     NewPosition             ;   and continue.
  149.  
  150. TabOver:
  151.         XCHG    BX,SwapBX               ;   Restore BX, put index into SwapBX
  152.         ADD     DL,8                    ; Advance cursor 8 spaces.
  153.         JMP     NewPosition             ;   and continue.
  154.  
  155. EndMsg:
  156.         XCHG    BX,SwapBX               ;   Restore BX, put index into SwapBX
  157.         POP     CX
  158.         RET                             ; Done here
  159.  
  160. ErrMsg  ENDP
  161.  
  162. ;-----------------------------------------------------------------------------
  163. ;        ClearScreen clears the entire screen
  164. ;-----------------------------------------------------------------------------
  165.  
  166. ClearScreen PROC NEAR
  167.         PUSH    AX                      ; Preserve the registers used
  168.         PUSH    BX
  169.         PUSH    CX
  170.         PUSH    DX
  171.  
  172.         MOV     AH,15                   ; Get Current Video Mode (page)
  173.         INT     10h                     ;   by calling BIOS.
  174.         MOV     BH,7                    ; Set display color
  175.  
  176.         MOV     AH,6                    ; Scroll Window Up
  177.         MOV     AL,0                    ;   Clear Screen
  178.         MOV     CH,0                    ;   top
  179.         MOV     CL,0                    ;   left
  180.         MOV     DH,24                   ;   bottom
  181.         MOV     DL,79                   ;   right
  182.         INT     10h                     ;   by calling BIOS.
  183.  
  184.         MOV     AH,15                   ; Get Current Video Mode (page)
  185.         INT     10h                     ;   by calling BIOS.
  186.         MOV     AH,2h                   ; Set Cursor Position
  187.         MOV     DX,0                    ;   to the top left corner
  188.         INT     10h                     ;   by calling BIOS.
  189.  
  190.         POP     DX                      ; Restore the registers.
  191.         POP     CX
  192.         POP     BX
  193.         POP     AX
  194.  
  195.         RET                             ; All done here.
  196. ClearScreen ENDP
  197.  
  198. ;-----------------------------------------------------------------------------
  199. ;        ParmString is called to get any command line parameters and process
  200. ;        them as needed.
  201. ;-----------------------------------------------------------------------------
  202.  
  203. ParmLen DB      0                       ; Number of parameter characters passed
  204.  
  205. MenuParm DB     ' Menu procedure for the COLOR program. '
  206.  
  207.         DB      10,13,' Reset to grey text, no border.  ',26
  208.  
  209. ParmString PROC NEAR
  210.  
  211.         ASSUME  CS:CODE, DS:CODE, ES:CODE, SS:CODE
  212.  
  213.         CLD                             ; Prepair for string movements.
  214.         MOV     AX,CS                   ; Get the code segment
  215.         MOV     ES,AX                   ;   to set ES
  216.         MOV     DS,AX                   ;   and DS to the same segment.
  217.  
  218. SetParm: MOV    SI,0080h                ; Address to search in PSP
  219.         MOV     DI,OFFSET ParmLen       ; Set destination for parameter string.
  220.         MOVSB                           ; Put in the parameter length byte.
  221.         MOV     CL,ParmLen              ; Transfer length byte to counter
  222.         MOV     CH,0                    ;   and make sure counter is set.
  223.         JCXZ    NoParm                  ; No parameters, so done here.
  224.         INC     CX                      ; Set counter for LOOP(E) functions
  225.         SUB     DX,DX                   ; Set DX to zero
  226.         SUB     BX,BX                   ; Set BX to zero
  227.         CALL    NewParm                 ; Get the text color
  228.         CMP     DL,0                    ; Color Specified ?
  229.         JE      NoParm                  ;   No parameters specified.
  230.         MOV     NewColor,DL             ;   Yes, so record it
  231.         SUB     AX,AX                   ; Set AX to zero
  232.         MOV     AL,DL                   ; Put color into AX
  233.         MOV     DX,0010h                ; Prepair for divide by 16
  234.         DIV     DL                      ; Get the background color
  235.         MOV     Border,AL               ;   for the border color default
  236.         SUB     DX,DX                   ; Set DX to zero
  237.         SUB     BX,BX                   ; Set BX to zero
  238.         MOV     ColrFlag,0              ; Reset flag
  239.         CALL    NewParm                 ; Get the border color
  240.         CMP     ColrFlag,0              ; Color Specified ?
  241.         JE      PutParm                 ;   No parameters specified.
  242.         MOV     Border,DL               ;   Yes, set the border color.
  243. PutParm: RET                            ; All done here.
  244.  
  245. NoParm: CALL    ShowHelp
  246.         RET                             ; All done here
  247.  
  248. ParmString ENDP
  249.  
  250. ;-----------------------------------------------------------------------------
  251. ;        NewParm checks the characters of a parameter.  If numeric, they are
  252. ;        converted to binary with result left in DX.
  253. ;-----------------------------------------------------------------------------
  254.  
  255. ColrFlag DB     0
  256. BadParm DB      9,' ERROR -- Color number non-numeric. ',26
  257. BigParm DB      9,' ERROR -- Color number too large. ',26
  258.  
  259. NewParm PROC    NEAR
  260.         LODSB                           ; Get the first character
  261.         CMP     AL,20h                  ; Is it a space ?
  262.         LOOPE   NewParm                 ;   Yes, so continue looking
  263.         JMP     RunParm                 ;   No, so skip down to check it out
  264. GetParm: LODSB                          ; Get the next character
  265.         CMP     AL,20h                  ; Is it a space ?
  266.         JE      EndParm                 ;   Yes, so end of parameter
  267. RunParm: CMP    AL,0Dh                  ; Carriage Return ?
  268.         JE      EndParm                 ;   Yes, so end of parameters
  269.         CMP     AL,30h                  ; Zero ?
  270.         JB      ParmBad                 ;   Below is a bad parm character
  271.         CMP     AL,39h                  ; Nine ?
  272.         JA      ParmBad                 ;   Above is a bad parm character
  273.         AND     AX,000Fh                ; Convert it to a decimal number.
  274.         MOV     ColrFlag,1              ; Got a valid number
  275.  
  276.         MOV     BX,DX                   ; Save the number (0 first time round)
  277.         SHL     DX,1                    ;   multiply by two
  278.         SHL     DX,1                    ;   multiply by two
  279.         ADD     DX,BX                   ;   add original number
  280.         SHL     DX,1                    ;   multiply by two ( = Times ten )
  281.  
  282.         ADD     DX,AX                   ; Add up the number
  283.         LOOP    GetParm                 ; Continue thru the number
  284.  
  285. EndParm: CMP    DX,00FFh                ; Is the number TOO BIG ?
  286.         JA      ParmBig                 ;   Yes, so EXIT with ERROR message
  287.         RET                             ;   No, so done here.
  288.  
  289. ParmBad: MOV    SwapBX,OFFSET BadParm   ; Point to message
  290.         MOV     SwapCX,40               ;   and set it's max length.
  291.         CALL    ErrMsg                  ; Display the message
  292.         MOV     AH,4Ch                  ; Terminate Process (return to DOS)
  293.         MOV     AL,0                    ;   with an ERROR LEVEL = 1
  294.         INT     21h                     ;   by calling DOS
  295. ;         INT    20h                    ; Fast way out instead of above.
  296.  
  297. ParmBig: MOV    SwapBX,OFFSET BigParm   ; Point to message
  298.         MOV     SwapCX,40               ;   and set it's max length.
  299.         CALL    ErrMsg                  ; Display the message
  300.         MOV     AH,4Ch                  ; Terminate Process (return to DOS)
  301.         MOV     AL,0                    ;   with an ERROR LEVEL = 1
  302.         INT     21h                     ;   by calling DOS
  303. ;         INT    20h                    ; Fast way out instead of above
  304.  
  305. NewParm ENDP
  306.  
  307. ;-----------------------------------------------------------------------------
  308. ;        ShowHelp displays a screen of help instructions
  309. ;-----------------------------------------------------------------------------
  310. SaveColor DB    0
  311.  
  312. HelpScreen DB   9,9,'C O L O R    P O W E R         by Crestwood Elite',13,10
  313.         DB      13,10
  314.         DB      9,'No color parameter was specified.  Use the table below to',13,10
  315.         DB      9,'see the color numbers.  Include the number on the command',13,10
  316.         DB      9,'line to set the screen default color.  You may optionally ',13,10
  317.         DB      9,'set the border color at the same time with a second number.',13,10
  318.         DB      13,10
  319.         DB      9,'COLOR 23 4      will set gray text on blue with a red border.',13,10
  320.         DB      13,10
  321.         DB      '┌────────┬───────────────────────────────────────────────────────────────┐',13,10
  322.         DB      '│ SCREEN │    TEXT colors     First = Normal      Second = Hi-Intensity  │',13,10
  323.         DB      '│ Bakgnd ├───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┤',13,10
  324.         DB      '│ Colors │ Black │ Blue  │ Green │ Cyan  │ Red   │Magenta│ Brown │ White │',13,10
  325.         DB      '├────────┼───────┼───────┼───────┼───────┼───────┼───────┼───────┼───────┤',13,10
  326.         DB      '│ Black  │  0   8│  1   9│  2  10│  3  11│  4  12│  5  13│  6  14│  7  15│',13,10
  327.         DB      '│ Blue   │ 16  24│ 17  25│ 18  26│ 19  27│ 20  28│ 21  29│ 22  30│ 23  31│',13,10
  328.         DB      '│ Green  │ 32  40│ 33  41│ 34  42│ 35  43│ 36  44│ 37  45│ 38  46│ 39  47│',13,10
  329.         DB      '│ Cyan   │ 48  56│ 49  57│ 50  58│ 51  59│ 52  60│ 53  61│ 54  62│ 55  63│',13,10
  330.         DB      '│ Red    │ 64  72│ 65  73│ 66  74│ 67  75│ 68  76│ 69  77│ 70  78│ 71  79│',13,10
  331.         DB      '│ Magenta│ 80  88│ 81  89│ 82  90│ 83  91│ 84  92│ 85  93│ 86  94│ 87  95│',13,10
  332.         DB      '│ Brown  │ 96 104│ 97 105│ 98 106│ 99 107│100 108│101 109│102 110│103 111│',13,10
  333.         DB      '│ White  │112 120│113 121│114 122│115 123│116 124│117 125│118 126│119 127│',13,10
  334.         DB      '└────────┴───────┴───────┴───────┴───────┴───────┴───────┴───────┴───────┘'
  335.         DB      32,26
  336.  
  337. ShowHelp PROC   NEAR
  338.         CALL    ClearScreen
  339.         MOV     Color,3                 ; Set color to cyan
  340.         MOV     SwapBX,OFFSET HelpScreen ; Point to message
  341.         MOV     SwapCX,756              ;   and set it's max length.
  342.         CALL    ErrMsg                  ; Display the message
  343.  
  344.         MOV     Color,0                 ; Set color
  345.         MOV     CX,8
  346.  
  347. MsgLoop: MOV    SwapCX,4                ;   and set it's max length.
  348.         CALL    ErrMsg                  ; Display the message
  349.  
  350.         ADD     Color,8                 ; Set color
  351.         MOV     SwapCX,3                ;   and set it's max length.
  352.         CALL    ErrMsg                  ; Display the message
  353.  
  354.         MOV     AL,Color
  355.         MOV     SaveColor,AL
  356.         MOV     Color,3                 ; Set color
  357.         MOV     SwapCX,1                ;   and set it's max length.
  358.         CALL    ErrMsg                  ; Display the message
  359.         MOV     AL,SaveColor
  360.         MOV     Color,AL
  361.  
  362.         SUB     Color,7                 ; Set color
  363.         LOOP    MsgLoop
  364.  
  365.         MOV     AL,Color
  366.         ADD     AL,8
  367.         MOV     SaveColor,AL
  368.         MOV     Color,3                 ; Set color
  369.         MOV     SwapCX,12               ;   and set it's max length.
  370.         CALL    ErrMsg                  ; Display the message
  371.         MOV     CX,8
  372.         MOV     AL,SaveColor
  373.         MOV     Color,AL
  374.         CMP     AL,119
  375.         JB      MsgLoop
  376.  
  377.         MOV     Color,3                 ; Set color
  378.         MOV     SwapCX,64               ;   and set it's max length.
  379.         CALL    ErrMsg                  ; Display the message
  380.         MOV     Color,7                 ; Set color
  381.         MOV     SwapCX,1                ;   and set it's max length.
  382.         CALL    ErrMsg                  ; Display the message
  383.  
  384.         MOV     AH,4Ch                  ; Terminate Process (return to DOS)
  385.         MOV     AL,0                    ;   with an ERROR LEVEL = 1
  386.         INT     21h                     ;   by calling DOS
  387. ;         INT    20h                    ; Fast way out instead of above
  388.  
  389. ShowHelp ENDP
  390.  
  391.  
  392. ;-----------------------------------------------------------------------------
  393. ;        Loader first checks if the program has already been loaded.
  394. ;          If it is ready, it initializes the new printer interrupt.
  395. ;-----------------------------------------------------------------------------
  396.  
  397. Loader: ASSUME  DS:CODE, ES:CODE, SS:CODE
  398.  
  399.         CALL    ParmString
  400.  
  401.         MOV     Header[33],'0'          ; Revision level prevents false match
  402.         MOV     Header[34],'1'
  403.         CLD
  404.         MOV     DX,CS                   ; This segment
  405.         SUB     AX,AX                   ; Beginning of search
  406.         MOV     ES,AX                   ; Search segment
  407.  
  408. SearchLoop:
  409.         MOV     SI,OFFSET Header        ; Address to search
  410.         MOV     CX,OFFSET Footer - OFFSET Header ; Length of search string
  411.         MOV     DI,SI                   ; Set pointers to same address
  412.         REPZ    CMPSB                   ; Check for match
  413.         JZ      AlreadyLoaded           ; If label matches, then already loaded
  414.  
  415.         INC     AX                      ; Still the search segment
  416.         MOV     ES,AX                   ; ES to next segment
  417.  
  418.         CMP     AX,DX                   ; Check if it's this segment
  419.         JNZ     SearchLoop              ; Try another compare
  420.  
  421.         JMP     MakeResident            ; Since no match found, proceed to
  422.                                         ;   set up and remain resident.
  423. AlreadyLoaded:
  424.         ADD     DI,OFFSET NewColor - OFFSET Footer ; Point to Colors in memory
  425.         ADD     SI,OFFSET NewColor - OFFSET Footer ; Point to Colors in memory
  426.         MOV     CX,2                    ; Reset the 2 colors
  427.         REP     MOVSB                   ;   by storing their values.
  428.  
  429.         CALL    ClearScreen             ; Display the new colors
  430.         MOV     AH,4Ch                  ; Terminate Process (return to DOS)
  431.         SUB     AL,AL                   ;   with an ERROR LEVEL = 0
  432.         INT     21h                     ;   by calling DOS
  433.  
  434. MakeResident:
  435.  
  436.         MOV     AH,35h                  ; Get Interrupt Vector address
  437.         MOV     AL,10h                  ;   for Video Services
  438.         INT     21h                     ;   by calling DOS.
  439.  
  440.         MOV     WORD PTR Int10h[2],ES   ; Transfer the vector base address
  441.         MOV     WORD PTR Int10h,BX      ;   and it's offset address
  442.  
  443.         PUSH    CS                      ; Set DS to this programs Code segment
  444.         POP     DS                      ;   for the new vector base address
  445.         MOV     DX,OFFSET Video         ;   and now it's offset
  446.         MOV     AH,25h                  ;   to set Interrupt Vector address
  447.         MOV     AL,10h                  ;   for Video Services
  448.         INT     21h                     ;   by calling DOS.
  449.  
  450.         CALL    ClearScreen             ; Clear the screen
  451.  
  452.         MOV     SwapBX,OFFSET Logo      ; Point to message
  453.         MOV     SwapCX,250              ;   and set it's max length.
  454.         CALL    ErrMsg                  ; Display the message
  455.         MOV     Color,0                 ; Set to original screen color
  456.  
  457. ;   NOTE: This procedure was deleted, proprietary material!
  458. ;         CALL   TellSize               ; Display the memory allocations
  459. ;   NOTE: This procedure was deleted, proprietary material!
  460.  
  461.         MOV     DX,OFFSET EndRes        ; Set to keep only the resident part.
  462.         INT     27h
  463.  
  464. Code    ENDS
  465.         END     Start
  466.     DX,OFFSET EndRes        ; Set to keep only the resident part.
  467.         INT     27h
  468.  
  469. Code    ENDS
  470.